<?php
/**
 * Created by PhpStorm.
 * User: Hanson
 * Date: 2016/11/5
 * Time: 1:33
 */

namespace App\Repository;


use App\Model\TemplateRecord;

class TemplateRepository
{

    public $template;

    public function __construct(TemplateRecord $templateRecord)
    {
        $this->template = $templateRecord;
    }

    public function all()
    {
        return $this->template->all();
    }

    public function search($payload = null)
    {
        $query = $this->template;

        if($payload['templateId'] ?? null){
            $query = $query->where('template_id', $payload['templateId']);
        }

        return $query->with('user')->with('user.class')->orderBy('id', 'desc')->paginate(20);
    }

}